<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadFiles.aspx.cs" Inherits="MyCustomModules_UploadFiles"  %>

<portal:HeadingControl ID="heading" runat="server" Text="Upload Files" Font-Size="Large"  />

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Upload File</title>
</head>
<body>
    <form id="form1" runat="server">
    <script language="javascript" type="text/javascript" >
        <!--
            function addNewBrowseControl(){
                var div = document.getElementById('<%=pnlFileNames.ClientID%>') ;
                
                var newBreak = document.createElement("br");
                var newFile = document.createElement("input");
                newFile.type = "file";
                newFile.style.width = "650px";
                //newFile.readOnly = "readonly";
                div.appendChild(newBreak);
                div.appendChild(newFile);

                return false;
            }
            
             function setAllFileNames(){
                var files = document.getElementById('<%=pnlFileNames.ClientID%>') ;
                
                var url = "<%=Request.RawUrl%>";
                var index = url.indexOf("?");
                if( index > 0 )
                    url = url.substring(0, index);
                                
                var strFileNames = "";
                var elms = files.getElementsByTagName("*");
                for(var i = 0, maxI = elms.length; i < maxI; ++i) {
                    var elm = elms[i];
                    if ( elm.type=="file")
                    {
                        if( elm.value != "")
                            strFileNames = strFileNames + elm.value + ";";
                    }
                    
                }
                
                window.location =  url+ "?filenames=" + strFileNames;
                return false;
            }
        //-->
    </script> 
    <div>
        <table border="1" width="100%" cellpadding="0" cellspacing="0" >
            <tr>
                <td>
                    <asp:Panel ID="pnlFileNames" runat="server" ></asp:Panel>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnAddMore" runat="server" Text="Add More Files"  OnClientClick="return addNewBrowseControl();"/>
                    <asp:HiddenField ID="hdnAllFileNames" runat="server" />
                    &nbsp;
                    <asp:Button ID="btnUploadAll" runat="server" Text="Save Files" OnClientClick="return setAllFileNames();" OnClick="btnUploadAll_Click" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
